package com.uy.cuantoconocesdeuruguay.listeners;

import android.graphics.Rect;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnTouchListener;

public class MainMenuButtonOnTouchListener implements OnTouchListener {
	private Rect rect; 
	private boolean exited = false;
	private static final float OPAQUE_ALPHA = 0.931640625f;//PRESSED
	private static final float LIGHT_ALPHA = 0.86328125f;//UNPRESSED
	@Override
	public boolean onTouch(View button, MotionEvent event) {
		if (event.getAction() == MotionEvent.ACTION_UP){
	    	exited = false;
	    }
		if (exited){
			return false;
		}
		button.setAlpha(LIGHT_ALPHA);
		if(event.getAction() == MotionEvent.ACTION_DOWN){
			rect = new Rect(button.getLeft(), button.getTop(), button.getRight(), button.getBottom());
			button.setAlpha(OPAQUE_ALPHA);
	    }else if(event.getAction() == MotionEvent.ACTION_MOVE){
	        if(rect.contains(button.getLeft() + (int) event.getX(), button.getTop() + (int) event.getY())){
				button.setAlpha(OPAQUE_ALPHA);
	        }else{
	        	exited = true;
	        }
	    }
		return false;
	}

}
